package com.neuedu.system.service.impl;
import lombok.RequiredArgsConstructor;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.neuedu.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.neuedu.system.domain.AAAAYunongFamilyMemberInfo;
import com.neuedu.system.mapper.AAAAYunongHouseholdInfoMapper;
import com.neuedu.system.domain.AAAAYunongHouseholdInfo;
import com.neuedu.system.service.IAAAAYunongHouseholdInfoService;

/**
 * 户主信息Service业务层处理
 *
 * @author ruoyi
 * @date 2024-12-18
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AAAAYunongHouseholdInfoServiceImpl extends ServiceImpl<AAAAYunongHouseholdInfoMapper, AAAAYunongHouseholdInfo> implements IAAAAYunongHouseholdInfoService
{
    private final AAAAYunongHouseholdInfoMapper aAAAYunongHouseholdInfoMapper;

    /**
     * 查询户主信息
     *
     * @param id 户主信息主键
     * @return 户主信息
     */
    @Override
    public AAAAYunongHouseholdInfo selectAAAAYunongHouseholdInfoById(Long id)
    {
        return aAAAYunongHouseholdInfoMapper.selectAAAAYunongHouseholdInfoById(id);
    }

    /**
     * 查询户主信息列表
     *
     * @param aAAAYunongHouseholdInfo 户主信息
     * @return 户主信息
     */
    @Override
    public List<AAAAYunongHouseholdInfo> selectAAAAYunongHouseholdInfoList(AAAAYunongHouseholdInfo aAAAYunongHouseholdInfo)
    {
        return aAAAYunongHouseholdInfoMapper.selectAAAAYunongHouseholdInfoList(aAAAYunongHouseholdInfo);
    }

    /**
     * 新增户主信息
     *
     * @param aAAAYunongHouseholdInfo 户主信息
     * @return 结果
     */
    @Transactional
    @Override
    public int insertAAAAYunongHouseholdInfo(AAAAYunongHouseholdInfo aAAAYunongHouseholdInfo)
    {
        int rows = aAAAYunongHouseholdInfoMapper.insertAAAAYunongHouseholdInfo(aAAAYunongHouseholdInfo);
        insertAAAAYunongFamilyMemberInfo(aAAAYunongHouseholdInfo);
        return rows;
    }

    /**
     * 修改户主信息
     *
     * @param aAAAYunongHouseholdInfo 户主信息
     * @return 结果
     */
    @Transactional
    @Override
    public int updateAAAAYunongHouseholdInfo(AAAAYunongHouseholdInfo aAAAYunongHouseholdInfo)
    {
        aAAAYunongHouseholdInfoMapper.deleteAAAAYunongFamilyMemberInfoByHouseholdId(aAAAYunongHouseholdInfo.getId());
        insertAAAAYunongFamilyMemberInfo(aAAAYunongHouseholdInfo);
        return aAAAYunongHouseholdInfoMapper.updateAAAAYunongHouseholdInfo(aAAAYunongHouseholdInfo);
    }

    /**
     * 批量删除户主信息
     *
     * @param ids 需要删除的户主信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteAAAAYunongHouseholdInfoByIds(Long[] ids)
    {
        aAAAYunongHouseholdInfoMapper.deleteAAAAYunongFamilyMemberInfoByHouseholdIds(ids);
        return aAAAYunongHouseholdInfoMapper.deleteAAAAYunongHouseholdInfoByIds(ids);
    }

    /**
     * 删除户主信息信息
     *
     * @param id 户主信息主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteAAAAYunongHouseholdInfoById(Long id)
    {
        aAAAYunongHouseholdInfoMapper.deleteAAAAYunongFamilyMemberInfoByHouseholdId(id);
        return aAAAYunongHouseholdInfoMapper.deleteAAAAYunongHouseholdInfoById(id);
    }

    /**
     * 新增家庭成员信息信息
     *
     * @param aAAAYunongHouseholdInfo 户主信息对象
     */
    public void insertAAAAYunongFamilyMemberInfo(AAAAYunongHouseholdInfo aAAAYunongHouseholdInfo)
    {
        List<AAAAYunongFamilyMemberInfo> aAAAYunongFamilyMemberInfoList = aAAAYunongHouseholdInfo.getAAAAYunongFamilyMemberInfoList();
        Long id = aAAAYunongHouseholdInfo.getId();
        if (StringUtils.isNotNull(aAAAYunongFamilyMemberInfoList))
        {
            List<AAAAYunongFamilyMemberInfo> list = new ArrayList<AAAAYunongFamilyMemberInfo>();
            for (AAAAYunongFamilyMemberInfo aAAAYunongFamilyMemberInfo : aAAAYunongFamilyMemberInfoList)
            {
                aAAAYunongFamilyMemberInfo.setHouseholdId(id);
                list.add(aAAAYunongFamilyMemberInfo);
            }
            if (list.size() > 0)
            {
                aAAAYunongHouseholdInfoMapper.batchAAAAYunongFamilyMemberInfo(list);
            }
        }
    }
}
